package io.renren.modules.book.controller;

import io.renren.common.utils.MinioUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;

@RestController
@RequestMapping("/minio")
public class MinioController {
    @RequestMapping("/upload")
    public String upload(MultipartFile file, String objectName) throws IOException {
        MinioUtils minioUtils = new MinioUtils();
        minioUtils.uploadToMinio(file.getInputStream(),objectName);
        return "ok";
    }
    @RequestMapping("/download")
    public String download(String fileName, String objectName,String dir) throws Exception {
        MinioUtils minioUtils = new MinioUtils();
        minioUtils.downloadImageFromMinioToFile(objectName,fileName,dir);
        return "ok";
    }
}
